<template>
  <div class="body1">
    <div class="no-print el-button-print">
      <el-button @click="exportPDF">导出为pdf</el-button>
    </div>
    <div class="body2" id="pdfDom" :class="{ 'pdf-export': isPdfExport }">
      <div class="title">
        <div class="biaotididian">{{ agencyName }}</div>
        <div class="biaoti">查封（扣押）现场笔录</div>
      </div>
      <div class="tableStyle1">
        <!-- 主体-->
        <div class="writ-height">
          <span>实施事由：</span>
          <input v-model="form.a1" :resize="'none'" autosize maxlength="27" class="inputStyle1"
            style="width: calc(27 * 5mm);font-family: 仿宋;font-size: 5mm;" type="textarea">
        </div>
        <div class="writ-height">
          <span>实施时间：</span>
          <editable-textarea :text="form.date1" param-type="YYYYMMDD1"
            @send-to-parent="receiveFromChild"></editable-textarea>
          <editable-textarea :text="form.time1" param-type="HH:mm1"
            @send-to-parent="receiveFromChild"></editable-textarea>
          <span>至</span>
          <editable-textarea :text="form.time2" param-type="HH:mm2"
            @send-to-parent="receiveFromChild"></editable-textarea>
        </div>
        <div class="writ-height">
          <span>实施地点：</span>
          <input v-model="form.a2" :resize="'none'" autosize maxlength="19" class="inputStyle1"
            style="width: calc(19 * 5mm);font-family: 仿宋;font-size: 5mm;" type="textarea">
          <span>天气：</span>
          <input v-model="form.a3" :resize="'none'" autosize maxlength="5" class="inputStyle1"
            style="width: calc(5 * 5mm);font-family: 仿宋;font-size: 5mm;" type="textarea">
        </div>
        <div class="writ-height" style="margin-bottom: 1px">
          <span>行政执法人员：</span>
          <InvestigatorSelect class="InvestigatorSelectReplace"
            style="height: 6mm; width: calc(9 * 5mm);margin-bottom: 4px;border-bottom: 1px solid black"
            v-model="form.a4" :id-field="'a5'" @change="handleInvestigatorChange" />
          <span>执法证件号：</span>
          <input v-model="form.a5" :resize="'none'" autosize class="inputStyle1" readonly
            style="width: calc(10 * 5mm);font-family: 仿宋;font-size: 5mm;" type="textarea" ref="inputRef6">
        </div>
        <div class="writ-height" style="margin-bottom: 1px">
          <span style="display: inline-block; width: 35mm;"></span>
          <InvestigatorSelect class="InvestigatorSelectReplace"
            style="height: 6mm; width: calc(9 * 5mm);margin-bottom: 4px;border-bottom: 1px solid black"
            v-model="form.a6" :id-field="'a7'" @change="handleInvestigatorChange" />
          <span>执法证件号：</span>
          <input v-model="form.a7" :resize="'none'" autosize class="inputStyle1" readonly
            style="width: calc(10 * 5mm);font-family: 仿宋;font-size: 5mm;" type="textarea" ref="inputRef6">
        </div>
        <div class="writ-height" style="margin-bottom: 1px">
          <span>记&nbsp;&nbsp;&nbsp;录&nbsp;&nbsp;&nbsp;人：</span>
          <InvestigatorSelect class="InvestigatorSelectReplace"
            style="height: 6mm; width: calc(9 * 5mm);margin-bottom: 4px;border-bottom: 1px solid black"
            v-model="form.a8" :id-field="'a9'" @change="handleInvestigatorChange" />
          <span>执法证件号：</span>
          <input v-model="form.a9" :resize="'none'" autosize class="inputStyle1" readonly
            style="width: calc(10 * 5mm);font-family: 仿宋;font-size: 5mm;" type="textarea" ref="inputRef6">
        </div>
        <div class="writ-height">
          <div style="display: inline-block; position: relative;">
            <span>当事人：</span>
            <privy-info-select-return-array v-model="form.unitName" v-model:isSelected="form.isUnit" :isTable="false"
              return-fields="A" :return-array-template="[
                { name: 'legalPerson', field: 'C' },
                { name: 'legalPersonPhone', field: 'H' },
                { name: 'companyAddress', field: 'E' },
              ]" :rowConfig="unitNameConfig" @select="selectUnitUpdateData">
            </privy-info-select-return-array>
          </div>
        </div>
        <div class="writ-height">
          <span>法定代表人或负责人：</span>
          <input v-model="form.legalPerson" :resize="'none'" autosize maxlength="11" class="inputStyle1"
            style="width: calc(11 * 5mm);font-family: 仿宋;font-size: 5mm;text-align: left;" type="textarea">
          <span>联系电话：</span>
          <input v-model="form.legalPersonPhone" :resize="'none'" autosize maxlength="12" class="inputStyle1"
            style="width: calc(6 * 5mm);font-family: 仿宋;font-size: 5mm;text-align: left;" type="textarea"
            oninput="this.value = this.value.replace(/[^a-zA-Z0-9_-]/g, '')">
        </div>
        <div class="writ-height">
          <span>住所(住址)：</span>
          <input v-model="form.companyAddress" :resize="'none'" autosize maxlength="26" class="inputStyle1"
            style="width: calc(26 * 5mm);font-family: 仿宋;font-size: 5mm;text-align: left;" type="textarea">
        </div>
        <div style="height: 140px; line-height: 30px;">
          <span>现场见证人：</span>
          <CrossRowInput v-model:value="form.a14" :line-config="a14Config"></CrossRowInput>
        </div>
        <div style="height: 285px; line-height: 30px;">
          <span>&nbsp;&nbsp;&nbsp;&nbsp;一、现场情况及告知事项：</span>
          <br>
          <span>&nbsp;&nbsp;&nbsp;&nbsp;对当事人涉嫌</span>
          <input v-model="form.a15" :resize="'none'" autosize maxlength="22" class="inputStyle1"
            style="width: calc(22 * 5mm);font-family: 仿宋;font-size: 5mm;" type="textarea">
          <span>的行为，行政执法人员依法实施查封（扣押）。</span>
          <br><span>&nbsp;&nbsp;&nbsp;&nbsp;<input v-model="form.a16" type="checkbox">1. 当事人在现场，行政执法人员向当事人：</span>
          <br><span>&nbsp;&nbsp;&nbsp;&nbsp;（1）出示行政执法证件；</span>
          <br><span>&nbsp;&nbsp;&nbsp;&nbsp;（2）告知采取查封（扣押）的理由是</span>
          <CrossRowInput v-model:value="form.a17" :line-config="a17Config"></CrossRowInput>
          <span>，根据</span>
          <CrossRowInput v-model:value="form.a18" :line-config="a18Config"></CrossRowInput>
          <span>的规定；</span>
          <br><span>&nbsp;&nbsp;&nbsp;&nbsp;（3）告知对采取的查封（扣押）如有异议的，可以进行陈述、申辩；</span>
          <br>
        </div>
        <div style="height: 110px; position: relative;">
          <div
            style="position: absolute; bottom: 80px; left: 0px; right: 20px; display: flex; justify-content: space-between; align-items: flex-end;">
            <div style="display: flex; align-items: flex-end;">
              <span>当事人（法定代表人或负责人）签名：</span>
              <span style="border-bottom: 1px solid black; padding-bottom: 6px;">
                <SignatureField label="签名1" sign-type="sign1" :img-url="form.img1"
                  @update:imgUrl="form.img1 = $event" />
              </span>
            </div>
            <div>
              <editable-textarea :text="form.date2" param-type="YYYYMMDD2"
                @send-to-parent="receiveFromChild"></editable-textarea>
            </div>
          </div>
          <div
            style="position: absolute; bottom: 45px; left: 0px; right: 20px; display: flex; justify-content: space-between; align-items: flex-end; ">
            <div style="display: flex; align-items: flex-end;">
              <span>现场见证人签名：</span>
              <span style="border-bottom: 1px solid black; padding-bottom: 6px;">
                <SignatureField label="签名2" sign-type="sign2" :img-url="form.img2"
                  @update:imgUrl="form.img2 = $event" />
              </span>
              ，
              <span style="border-bottom: 1px solid black; padding-bottom: 6px;">
                <SignatureField label="签名3" sign-type="sign3" :img-url="form.img3"
                  @update:imgUrl="form.img3 = $event" />
              </span>

            </div>
            <div>
              <editable-textarea :text="form.date3" param-type="YYYYMMDD3"
                @send-to-parent="receiveFromChild"></editable-textarea>
            </div>
          </div>
          <div
            style="position: absolute; bottom: 10px; left: 0px; right: 20px; display: flex; justify-content: space-between; align-items: flex-end; ">
            <div style="display: flex; align-items: flex-end;">
              <span>行政执法人员签名：</span>
              <span style="border-bottom: 1px solid black; padding-bottom: 6px;">
                <SignatureField label="签名4" sign-type="sign4" :img-url="form.img4"
                  @update:imgUrl="form.img4 = $event" />
              </span>
              ，
              <span style="border-bottom: 1px solid black; padding-bottom: 6px;">
                <SignatureField label="签名5" sign-type="sign5" :img-url="form.img5"
                  @update:imgUrl="form.img5 = $event" />
              </span>
            </div>
            <div>
              <editable-textarea :text="form.date4" param-type="YYYYMMDD4"
                @send-to-parent="receiveFromChild"></editable-textarea>
            </div>
          </div>
        </div>
        <div class="writ-height">
          <span>备注：</span>
          <input v-model="form.a42" :resize="'none'" autosize maxlength="29" class="inputStyle2"
            style="width: calc(29 * 5mm);font-family: 仿宋;font-size: 5mm;" type="textarea">
        </div>
        <div class="page-number-div">
          <span>第1页/共2页</span>
        </div>
      </div>
      <div class="page-break">
        <div class="tableStyle2">
          <div style="height: 740px; line-height: 30px;">
            <span>&nbsp;&nbsp;&nbsp;&nbsp;（4）告知如对本查封（扣押）不服，可以在收到决定书之日起60日内向</span>
            <input v-model="form.a19" :resize="'none'" autosize maxlength="18" class="inputStyle1"
              style="width: calc(18 * 5mm);font-family: 仿宋;font-size: 5mm;" type="textarea">
            <span>申请行政复议，也可以在收到决定书之日起6个月内直接向</span>
            <input v-model="form.a20" :resize="'none'" autosize maxlength="11" class="inputStyle1"
              style="width: calc(11 * 5mm);font-family: 仿宋;font-size: 5mm;" type="textarea">
            <span>人民法院提起诉讼。</span>
            <br><span>&nbsp;&nbsp;&nbsp;&nbsp;<input v-model="form.a21" type="checkbox">2. 当事人不在现场：</span>
            <br><span>&nbsp;&nbsp;&nbsp;&nbsp;行政执法人员邀请现场见证人</span>
            <input v-model="form.a22" :resize="'none'" autosize maxlength="14" class="inputStyle1"
              style="width: calc(14 * 5mm);font-family: 仿宋;font-size: 5mm;" type="textarea">
            <span>到场，并出示行政执法证件。</span>
            <br><span>&nbsp;&nbsp;&nbsp;&nbsp;二、当事人的陈诉、申辩情况：</span>
            <br><span>&nbsp;&nbsp;&nbsp;&nbsp;<input v-model="form.a23" type="checkbox">当事人未进行陈诉、申辩。</span>
            <br><span>&nbsp;&nbsp;&nbsp;&nbsp;<input v-model="form.a24" type="checkbox">当事人进行了陈诉、申辩，称：</span>
            <CrossRowInput v-model:value="form.a25" :line-config="a25Config"></CrossRowInput>
            <br><span>&nbsp;&nbsp;&nbsp;&nbsp;三、现场处理情况：</span>
            <br><span>&nbsp;&nbsp;&nbsp;&nbsp;<input v-model="form.a26"
                type="checkbox"><span>行政执法人员听取当事人的陈诉、申辩后，认为</span></span>
            <CrossRowInput v-model:value="form.a27" :line-config="a26Config"></CrossRowInput>。
            <br><span>&nbsp;&nbsp;&nbsp;&nbsp;<input v-model="form.a28" type="checkbox"><span>行政执法人员对</span></span>
            <CrossRowInput v-model:value="form.a29" :line-config="a29Config"></CrossRowInput>
            <span>实施了查封（扣押）。</span>
            <br>
            <span>&nbsp;&nbsp;&nbsp;&nbsp;</span><input v-model="form.a30" type="checkbox">
            <span>行政执法人员作出了《查封（扣押）决定书》（</span>
            <input v-model="form.a31" :resize="'none'" autosize maxlength="4" class="inputStyle1"
              style="width: 80px;font-family: 仿宋;font-size: 5mm;text-align: center" type="textarea">
            <span>（</span>
            <reference-select style="width: 5mm;margin-bottom: 4px" v-model="form.referenceValue"
              class="InvestigatorSelectReplace" />
            <span>）查（扣）决字[</span>
            <input v-model="form.a32" :resize="'none'" autosize maxlength="4" class="areaInputStyle"
              style="width: 40px;font-family: 仿宋;font-size: 5mm;text-align: center" type="textarea"
              oninput="this.value = this.value.replace(/[^a-zA-Z0-9_-]/g, '')">
            <span>]第</span>
            <input v-model="form.a33" :resize="'none'" autosize maxlength="5" class="areaInputStyle"
              style="width: 50px;font-family: 仿宋;font-size: 5mm;text-align: center" type="textarea"
              oninput="this.value = this.value.replace(/[^a-zA-Z0-9_-]/g, '')">
            <span>号），并交由</span>
            <input v-model="form.a34" :resize="'none'" autosize maxlength="6" class="inputStyle1"
              style="width: calc(6 * 5mm);font-family: 仿宋;font-size: 5mm;" type="textarea">
            <span>签名确认。</span>
            <br>
            <span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
            <input v-model="form.a35" type="checkbox">
            <span>行政执法人员当场向当事人交付上述《查封（扣押）决定书》（</span>
            <input v-model="form.a36" :resize="'none'" autosize maxlength="4" class="inputStyle1"
              style="width: 80px;font-family: 仿宋;font-size: 5mm;text-align: center" type="textarea">
            <span>（</span>
            <reference-select style="width: 5mm;margin-bottom: 4px" v-model="form.referenceValue"
              class="InvestigatorSelectReplace" />
            <span>）查（扣）决字[</span>
            <input v-model="form.a37" :resize="'none'" autosize maxlength="4" class="areaInputStyle"
              style="width: 40px;font-family: 仿宋;font-size: 5mm;text-align: center" type="textarea"
              oninput="this.value = this.value.replace(/[^a-zA-Z0-9_-]/g, '')">
            <span>]第</span>
            <input v-model="form.a38" :resize="'none'" autosize maxlength="5" class="areaInputStyle"
              style="width: 50px;font-family: 仿宋;font-size: 5mm;text-align: center" type="textarea"
              oninput="this.value = this.value.replace(/[^a-zA-Z0-9_-]/g, '')">
            <span>号）。</span>
            <br>&nbsp;&nbsp;&nbsp;&nbsp;<input v-model="form.a39" type="checkbox"><span>行政执法人员对实施查封（扣押）的过程进行了拍摄。</span>
            <br>&nbsp;&nbsp;&nbsp;&nbsp;<input v-model="form.a40" type="checkbox">
            <el-select v-model="form.a41" placeholder="" class="already-know-select">
              <el-option label="上述笔录内容我已看过，记录属实。" value="1" class="already-know-option"></el-option>
              <el-option label="上述笔录内容我已看过，记录有误。" value="2" class="already-know-option"></el-option>
            </el-select>
          </div>

          <div style="height: 140px; position: relative;">
            <div
              style="position: absolute; bottom: 80px; left: 0px; right: 20px; display: flex; justify-content: space-between; align-items: flex-end;">
              <div style="display: flex; align-items: flex-end;">
                <span>当事人（法定代表人或负责人）签名：</span>
                <span style="border-bottom: 1px solid black; padding-bottom: 6px;">
                  <SignatureField label="签名6" sign-type="sign6" :img-url="form.img6"
                    @update:imgUrl="form.img6 = $event" />
                </span>
              </div>
              <div>
                <editable-textarea :text="form.date5" param-type="YYYYMMDD5"
                  @send-to-parent="receiveFromChild"></editable-textarea>
              </div>
            </div>
            <div
              style="position: absolute; bottom: 45px; left: 0px; right: 20px; display: flex; justify-content: space-between; align-items: flex-end; ">
              <div style="display: flex; align-items: flex-end;">
                <span>现场见证人签名：</span>
                <span style="border-bottom: 1px solid black; padding-bottom: 6px;">
                  <SignatureField label="签名7" sign-type="sign7" :img-url="form.img7"
                    @update:imgUrl="form.img7 = $event" />
                </span>
                ，
                <span style="border-bottom: 1px solid black; padding-bottom: 6px;">
                  <SignatureField label="签名8" sign-type="sign8" :img-url="form.img8"
                    @update:imgUrl="form.img8 = $event" />
                </span>

              </div>
              <div>
                <editable-textarea :text="form.date6" param-type="YYYYMMDD6"
                  @send-to-parent="receiveFromChild"></editable-textarea>
              </div>
            </div>
            <div
              style="position: absolute; bottom: 10px; left: 0px; right: 20px; display: flex; justify-content: space-between; align-items: flex-end; ">
              <div style="display: flex; align-items: flex-end;">
                <span>行政执法人员签名：</span>
                <span style="border-bottom: 1px solid black; padding-bottom: 6px;">
                  <SignatureField label="签名9" sign-type="sign9" :img-url="form.img9"
                    @update:imgUrl="form.img9 = $event" />
                </span>
                ，
                <span style="border-bottom: 1px solid black; padding-bottom: 6px;">
                  <SignatureField label="签名10" sign-type="sign10" :img-url="form.img10"
                    @update:imgUrl="form.img10 = $event" />
                </span>
              </div>
              <div>
                <editable-textarea :text="form.date7" param-type="YYYYMMDD7"
                  @send-to-parent="receiveFromChild"></editable-textarea>
              </div>
            </div>
          </div>
          <div class="writ-height">
            <span>备注：</span>
            <input v-model="form.a43" :resize="'none'" autosize maxlength="29" class="inputStyle2"
              style="width: calc(29 * 5mm);font-family: 仿宋;font-size: 5mm;" type="textarea">
          </div>
          <div class="page-number-div">
            <span>第2页/共2页</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import EditableTextarea from "@/views/template/EditableTextarea";
import { agencyName, sealName } from "../../utils/publicName.js";
import PrivyInfoSelectReturnArray from "@/views/template/PrivyInfoSelectReturnArray";
import InvestigatorSelect from "@/views/template/InvestigatorSelect";
import CrossRowInput from "@/views/template/CrossRowInput";
import SignatureField from "@/views/template/SignatureField";
import ReferenceSelect from "@/views/template/ReferenceSelect";


export default {
  components: {
    EditableTextarea,
    InvestigatorSelect,
    CrossRowInput,
    SignatureField,
    ReferenceSelect,
    PrivyInfoSelectReturnArray,
  },

  data() {
    return {
      agencyName: agencyName,
      sealName: sealName,
      form: {
        continuationSheet: [],
      },
      status: '', //当前文书的状态
      isPdfExport: false, //控制打印样式
      unitNameConfig: {
        firstLine: { chars: 28 * 2 },
        middleLines: { count: 0, chars: 32 * 2 },
        lastLine: { chars: 0 * 2 }
      },
      a14Config: {
        firstLine: { chars: 26 * 2 },
        middleLines: { count: 2, chars: 32 * 2 },
        lastLine: { chars: 32 * 2 }
      },
      a17Config: {
        firstLine: { chars: 13 * 2 },
        middleLines: { count: 0, chars: 32 * 2 },
        lastLine: { chars: 12 * 2 }
      },
      a18Config: {
        firstLine: { chars: 17 * 2 },
        middleLines: { count: 0, chars: 32 * 2 },
        lastLine: { chars: 28 * 2 }
      },
      a25Config: {
        firstLine: { chars: 15 * 2 },
        middleLines: { count: 3, chars: 32 * 2 },
        lastLine: { chars: 32 * 2 }
      },
      a26Config: {
        firstLine: { chars: 8 * 2 },
        middleLines: { count: 0, chars: 32 * 2 },
        lastLine: { chars: 17 * 2 }
      },
      a27Config: {
        firstLine: { chars: 8 * 2 },
        middleLines: { count: 0, chars: 32 * 2 },
        lastLine: { chars: 31 * 2 }
      },
      a29Config: {
        firstLine: { chars: 22 * 2 },
        middleLines: { count: 0, chars: 32 * 2 },
        lastLine: { chars: 22 * 2 }
      },
    }
  },

  created() {
    window.parent.getTemplateData((data, status) => {
      this.form = data;
      this.status = status;
    })
    window.postForm = () => {
      this.postForm();
    }
  },

  mounted() {
    window.parent.changeTemplateDow();
  },

  methods: {
    // 导出为pdf
    exportPDF() {
      this.savePDF()
        .then((blob) => {

          const blobUrl = URL.createObjectURL(blob);

          // 先预览
          const previewWindow = window.open(blobUrl, '_blank');

          // 自动下载
          const fileName = `查封（扣押）现场笔录.pdf`;
          const downloadLink = document.createElement('a');
          downloadLink.href = blobUrl;
          downloadLink.download = fileName;
          document.body.appendChild(downloadLink);
          downloadLink.click();
          document.body.removeChild(downloadLink);

          // 监听预览窗口关闭后释放内存
          if (previewWindow) {
            const timer = setInterval(() => {
              if (previewWindow.closed) {
                clearInterval(timer);
                URL.revokeObjectURL(blobUrl);
              }
            }, 1000);
          } else {
            setTimeout(() => URL.revokeObjectURL(blobUrl), 10000); // 兜底释放
          }
        })
        .catch(error => {
          console.error('导出PDF出错:', error);
          alert('导出失败，请重试或联系管理员');
        });
    },
    savePDF() {
      this.isPdfExport = true; // 激活PDF样式
      return new Promise((resolve, reject) => {
        this.$nextTick(() => {
          import('html2pdf.js').then((module) => {
            const html2pdf = module.default;

            //获取所有需要替换的 el-input
            const elInputs = document.querySelectorAll('.el-textarea-hidden .el-input__inner, .el-textarea-hidden .el-textarea__inner');

            //存储原始元素和它们的父节点，方便后续恢复
            const originalElements = [];

            elInputs.forEach((input) => {
              const div = document.createElement('div');
              div.style.whiteSpace = 'pre-wrap'; // 保留换行
              div.style.fontFamily = '仿宋';
              div.style.fontSize = '19px';
              div.style.height = '100%';
              div.style.width = '100%';

              div.textContent = input.value; // 保留原内容（自动处理 \n 换行）
              div.style.lineHeight = '30px';
              div.style.backgroundImage = 'linear-gradient(to top, #000 1px, transparent 1px)';
              div.style.backgroundSize = '100% 30px';
              div.style.backgroundRepeat = 'repeat-y';
              div.style.backgroundPosition = '0 -3px';
              div.style.padding = '0';
              div.style.boxSizing = 'border-box';


              // 替换 el-input，并存储原始元素
              originalElements.push({
                parent: input.parentNode,
                original: input,
                replacement: div,
              });
              input.parentNode.replaceChild(div, input);
            });

            // 处理选择执法人的替换
            const InvestigatorSelectSelects = document.querySelectorAll('.InvestigatorSelectReplace .el-input__inner, .InvestigatorSelectReplace .el-textarea__inner');
            InvestigatorSelectSelects.forEach((input) => {
              const div = document.createElement('div');
              div.style.whiteSpace = 'pre-wrap'; // 保留换行
              div.style.fontFamily = '仿宋';
              div.style.fontSize = '5mm';
              div.textContent = input.value; // 保留原内容（自动处理 \n 换行）
              div.style.lineHeight = '1.3';

              // 替换 el-input，并存储原始元素
              originalElements.push({
                parent: input.parentNode,
                original: input,
                replacement: div,
              });
              input.parentNode.replaceChild(div, input);
            });

            // 配置选项
            const opt = {
              margin: 0,
              image: {
                type: 'jpeg',
                quality: 0.98
              },
              html2canvas: {
                scale: 2,
                logging: false,
                useCORS: true
              },
              jsPDF: {
                unit: 'mm',
                format: 'a4',
                orientation: 'portrait'
              }
            };

            const element = document.getElementById('pdfDom');

            // 生成PDF Blob对象
            html2pdf()
              .set(opt)
              .from(element)
              .toPdf()
              .get('pdf')
              .then((pdf) => {
                const blob = pdf.output('blob');

                resolve(blob); // 返回Blob对象
              })
              .catch((error) => {
                reject(error);
              })
              .finally(() => {
                this.isPdfExport = false; // 恢复原始样式
                // 恢复原始input
                originalElements.forEach(({ parent, original, replacement }) => {
                  parent.replaceChild(original, replacement);
                });
              });
          }).catch((error) => {
            reject(error);
            this.isPdfExport = false;
            originalElements.forEach(({ parent, original, replacement }) => {
              parent.replaceChild(original, replacement);
            });
          });
        });
      });
    },
    //父页面提交按钮将调用此方法，此方法将文书数据回传到父页面的请求方法中
    postForm() {
      this.savePDF()
        .then((blob) => {


          // 创建FormData并添加文件
          const formData = new FormData();
          formData.append('file', blob, '查封（扣押）现场笔录.pdf');

          window.parent.postTemplateDate(this.form, formData);
        })
        .catch(error => {
          console.error('整个保存PDF出错:', error);
        });
    },
    //选择日期时间
    receiveFromChild(data, type) {
      const TypeMap = {
        'HH:mm1': 'time1',
        'HH:mm2': 'time2',
        'YYYYMMDD1': 'date1',
        'YYYYMMDD2': 'date2',
        'YYYYMMDD3': 'date3',
        'YYYYMMDD4': 'date4',
        'YYYYMMDD5': 'date5',
        'YYYYMMDD6': 'date6',
        'YYYYMMDD7': 'date7',
      };
      if (TypeMap[type]) {
        this.form[TypeMap[type]] = data;
      }
    },
    //选择执法人员
    handleInvestigatorChange({ identificationNumber, idField }) {
      if (idField && identificationNumber) {
        this.form[idField] = identificationNumber;
      }
    },
    // 选择单位
    selectUnitUpdateData(data) {
      data.forEach(item => {
        this.form[item.name] = item.value;
      })
    },
  }
}
</script>

<style scoped>
:deep(.el-button-print .el-button) {
  display: inline-flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  width: auto;
  min-width: 100px;
  height: auto;
  padding: 8px 15px;
  background: #fff !important;
  color: #000 !important;
  border: none;
}

:deep(.el-textarea__inner) {
  box-shadow: 0 0 0 0;
  color: black;
  padding: 0;
  font-family: "仿宋", serif;
  font-size: 5mm;
  overflow-y: hidden;
  line-height: 1.6;

  /* 下划线 */
  border-radius: 0px;
  background-image: linear-gradient(to top, #000000 0.5px, transparent 1px);
  background-size: 100% 1.6em;
  background-position: 0 -3px;
}

:deep(.el-textarea-hidden .el-textarea__inner) {
  box-shadow: 0 0 0 0;
  color: black;
  padding: 0;
  font-family: "仿宋", serif;
  font-size: 5mm;
  overflow-y: hidden !important;
  resize: none !important;
  height: auto !important;
}

:deep(.el-select .el-input__inner) {
  text-align: center;
  height: 5mm;
}

.input-container {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
}

.inputStyleNoLine {
  border: none;
  outline: none;
  padding: 0px;
}

.typeSpan {
  cursor: pointer;
  font-size: 5mm;
}

/* 完全移除选择框的所有边框和阴影 */
.already-know-select {
  border-bottom: 1px solid #000;
  width: 300px;
  margin: 0;
  padding: 0;
}

:deep(.already-know-select .el-input__wrapper) {
  box-shadow: none !important;
  border: none !important;
  padding: 0px !important;

}

/* 处理聚焦状态 */
:deep(.already-know-select .el-input__wrapper:focus-within) {
  box-shadow: none !important;
  border: none !important;
}

:deep(.already-know-select .el-input__inner) {
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
  font-family: "仿宋", "FangSong", serif !important;
  font-size: 18px !important;
  padding: 0 0px !important;
  color: black !important;
  background-color: transparent !important;
  height: auto !important;
  line-height: 24px !important;
  text-align: left !important;
}

/* 移除提示语 */
:deep(.already-know-select .el-input__inner::placeholder) {
  color: transparent !important;
}

/* 移除下拉箭头 */
:deep(.already-know-select .el-input__suffix) {
  display: none !important;
}

/* 移除聚焦状态下的边框 */
:deep(.already-know-select .el-input__inner:focus) {
  border: none !important;
  box-shadow: 0 0 0 0 !important;
}

/* 下拉面板样式 */
.inspector-popper {
  border: none !important;
  box-shadow: none !important;
  font-family: "仿宋", "FangSong", serif !important;
  font-size: 5mm !important;
}

/* 下拉选项样式 */
:deep(.inspector-popper .el-select-dropdown__item) {
  font-family: "仿宋", "FangSong", serif !important;
  font-size: 5mm !important;
  height: auto !important;
  padding: 5px 10px !important;
}

/* 选中项样式 */
:deep(.inspector-popper .el-select-dropdown__item.selected) {
  color: #000 !important;
  font-weight: normal !important;
  background-color: #f5f5f5 !important;
}
</style>
